﻿#include "comalgor.h"
#include "commons.h"

ComAlgor::ComAlgor(QObject *parent) : QObject(parent)
{

}

ComAlgor::~ComAlgor()
{

}
uint16_t ComAlgor::crcVal(unsigned char *pcMess,unsigned int wLen)
{
    unsigned int Index;
    uint16_t nCRCData;
    nCRCData=0xffff;
    while(wLen--) {
        Index=nCRCData>>8;
        Index=Index^(*pcMess++&0x00ff);
        nCRCData=(nCRCData^CrcTbl[Index])&0x00ff;
        nCRCData=(nCRCData<<8)|(CrcTbl[Index]>>8);
    }
    return (nCRCData>>8|nCRCData<<8);
}
uint16_t  ComAlgor::CRC16(const unsigned char *buf, unsigned int len)
{
 uint16_t crc = 0xaa;//初值为0xaa
 while(len--){
 crc = (crc<<8) ^ crc16tab[((crc>>8) ^ *(unsigned char *)buf++)&0x00FF];
 }
 return crc;
}
